<?php $__env->startSection('title'); ?>
    <li <?php if($level == 2): ?>class="cur"<?php endif; ?>>
        <a href="/lar/develop/permission/group?level=2"><span>二级权限组</span></a>
    </li>
    <li <?php if($level == 1): ?>class="cur"<?php endif; ?>>
        <a href="/lar/develop/permission/group?level=1"><span>一级权限组</span></a>
    </li>
<?php $__env->stopSection(); ?>

<?php $__env->startSection('btn'); ?>
    <button class="btn btn-primary" type="button" onclick="PermissionGroup.edit();">添加权限组</button>
<?php $__env->stopSection(); ?>

<?php $__env->startSection('search'); ?>

    <select name="parent_id" class="form-control">
        <option value="0">一级权限组</option>
        <?php if(!empty($group)): ?>
            <?php foreach($group as $g): ?>
                <option value="<?php echo e($g['group_id']); ?>"><?php echo e($g['group_name']); ?></option>
            <?php endforeach; ?>
        <?php endif; ?>
    </select>
    <input type="text" class="form-control" name="group_name" placeholder="权限组名称">

<?php $__env->stopSection(); ?>

<?php $__env->startSection('js'); ?>
    <script>

        var bootstrap_table_ajax_url = '/lar/develop/permission/group/search?level=<?php echo e($level); ?>';
        bootstrap_table({
            sortName: 'sort',
            sortOrder: 'ASC',
            columns: [
                {title: '操作', field: 'operation', align: 'center',width: '150px'},
                <?php if($level == 2): ?>
                {title: '二级权限组名称', field: 'group_name', align: 'left'},
                {title: '一级权限组名称', field: 'parent_group_name', align: 'left'},
                <?php else: ?>
                {title: '权限组名称', field: 'group_name', align: 'left'},
                <?php endif; ?>
                {title: '最小权限ID', field: 'min_permission_id', align: 'center'},
                {title: '最大权限ID', field: 'max_permission_id', align: 'center'},
                {title: '权限数量', field: 'permission_num', align: 'center'},
                {title: '排序序号', field: 'sort', align: 'center'}
            ]
        });

        var PermissionGroup = {

            level: <?php echo e($level); ?>,

            edit: function (id) {

                <?php if($level == 1): ?>
                var title = '一级权限组';
                <?php else: ?>
                var title = '二级权限组';
                <?php endif; ?>

                var html = '<form onsubmit="return false;" class="form-horizontal" id="permission-form" style="margin-top: 15px;">';

                html += '<input type="hidden" id="group_id" name="group_id" value="0">';

                <?php if($level == 1): ?>
                html += '<input type="hidden" id="parent_id" name="parent_id" value="0">';
                <?php else: ?>
                html += '<div class="form-group">';
                html += '<label for="group_name" class="col-sm-4 control-label"><span class="red">*</span> 一级权限组：</label>';
                html += '<div class="col-sm-8">';
                html += '<select class="form-control" id="parent_id" name="parent_id">';
                html += '<option value="0">请选择一级权限组</option>';
                <?php if(!empty($group)): ?>
                    <?php foreach($group as $g): ?>
                    html += '<option value="<?php echo e($g['group_id']); ?>"><?php echo e($g['group_name']); ?></option>';
                    <?php endforeach; ?>
                <?php endif; ?>
                html += '</select>';
                html += '</div>';
                html += '</div>';
                <?php endif; ?>

                html += '<div class="form-group">';
                html += '<label for="group_name" class="col-sm-4 control-label"><span class="red">*</span> 权限组名称：</label>';
                html += '<div class="col-sm-8">';
                html += '<input type="text" class="form-control" id="group_name" name="group_name" placeholder="请输入权限组名称">';
                html += '</div>';
                html += '</div>';

                html += '<div class="form-group">';
                html += '<label for="group_name" class="col-sm-4 control-label"><span class="red">*</span> 最小权限ID：</label>';
                html += '<div class="col-sm-8">';
                html += '<input type="text" class="form-control" id="min_permission_id" name="min_permission_id" placeholder="请输入最小权限ID">';
                html += '</div>';
                html += '</div>';

                html += '<div class="form-group">';
                html += '<label for="group_name" class="col-sm-4 control-label"><span class="red">*</span> 最大权限ID：</label>';
                html += '<div class="col-sm-8">';
                html += '<input type="text" class="form-control" id="max_permission_id" name="max_permission_id" placeholder="请输入最大权限ID">';
                html += '</div>';
                html += '</div>';

                html += '<div class="form-group">';
                html += '<label for="group_name" class="col-sm-4 control-label"><span class="red">*</span> 排序序号：</label>';
                html += '<div class="col-sm-8">';
                html += '<input type="text" class="form-control" id="sort" name="sort" placeholder="请输入排序序号">';
                html += '</div>';
                html += '</div>';

                html += '</form>';

                var layer_layer = layer.open({
                    title: title,
                    type: 1,
                    area: ['400px'],
                    offset: '20px',
                    content: html,
                    btn: ['保存', '关闭'],
                    yes: function () {

                        var dt = E.getFormValues('permission-form');
                        var msg = '';

                        if (PermissionGroup.level == 2 && dt.parent_id == 0) {
                            msg += '请选择一级权限组<br>';
                        }

                        if (E.isEmpty(dt.group_name)) {
                            msg += '请输入权限组名称<br>';
                        }

                        if (!E.isDigital(dt.min_permission_id)) {
                            msg += '请输入最小权限ID<br>';
                        }

                        if (!E.isDigital(dt.max_permission_id)) {
                            msg += '请输入最大权限ID<br>';
                        }

                        if (!E.isDigital(dt.sort)) {
                            msg += '请输入排序序号<br>';
                        }

                        if (msg != '') {
                            layer.alert(msg, {icon: 2});
                            return false;
                        }

                        dt.level = PermissionGroup.level;

                        E.ajax({
                            type: 'POST',
                            url: '/lar/develop/permission/group/store',
                            data: dt,
                            success: function (res) {
                                if (res.code == 200) {
                                    layer.alert('权限组保存成功', {icon: 1, time: 1500});
                                    if (dt.group_id > 0) {
                                        layer.close(layer_layer);
                                    } else {
                                        document.getElementById('permission-form').reset();
                                    }
                                    bootstrap_table_init();
                                } else {
                                    layer.alert(res.message, {icon: 2});
                                }
                            }
                        });

                    },
                    scrollbar: false
                });
                
                if (id) {
                    E.ajax({
                        type: 'GET',
                        url: '/lar/develop/permission/group/' + id,
                        success: function (res) {
                            if (res.code == 200) {
                                $('#group_id').val(res.data.group_id);
                                $('#parent_id').val(res.data.parent_id);
                                $('#group_name').val(res.data.group_name);
                                $('#min_permission_id').val(res.data.min_permission_id);
                                $('#max_permission_id').val(res.data.max_permission_id);
                                $('#sort').val(res.data.sort);
                            } else {
                                layer.alert(res.message, {icon: 2});
                                layer.close(layer_layer);
                            }
                        }
                    });
                }

            },

            del: function (id) {

                layer.confirm('您确认删除该权限组吗？<br>删除权限组同时会删除对应的权限', {icon: 3}, function (index) {
                    layer.close(index);
                    E.ajax({
                        type: 'GET',
                        url: '/lar/develop/permission/group/delete/' + id,
                        success: function (res) {
                            if (res.code == 200) {
                                layer.alert('删除成功', {icon: 1, time: 1500});
                                bootstrap_table_init();
                            } else {
                                layer.alert(res.message, {icon: 2});
                            }
                        }
                    });
                });

            }

        };


        var Deposit  = {

            //手工充值
            edit: function (  ) {
                layer.open({
                    title: false,
                    type: 2,
                    area: ['100%', '100%'],
                    closeBtn: false,
                    scrollbar: false,
                    content: '/sms-admin/deposit/edit'
                });

            },


            //详情
            detail :function(id){
                if ( id) {

                    layer.open( {
                        title: false,
                        type: 2 ,
                        area: ['100%', '100%'] ,
                        offset: '0px' ,
                        content: '/sms-admin/deposit/detail/'+id ,
                        closeBtn: false,
                        scrollbar: false
                    } )

                } else {
                    layer.alert('参数错误',{icon:2});
                    return false;
                }
            },


            //关闭订单
            close:function( id ) {


                layer.confirm( '您确定关闭该账户吗？' , {icon:3,offset:'50px'},function(index){

                    layer.close( index );

                    E.ajax({
                        type: 'get',
                        url: '/sms-admin/deposit/close/'+id,
                        data: { 'id': id } ,

                        success: function (res) {

                            if (res.code == 200) {
                                layer.alert('账户关闭成功', {icon: 1, offset: '70px', time: 1000});
                                bootstrap_table_init();

                            } else {
                                layer.msg(res.message, {icon: 2, offset: '70px'});
                            }
                        }
                    });
                })

            },

            //导出
            export:function(){
                var searchForm = document.getElementById('search-form');
                searchForm.action = '/excel/export/6';
                searchForm.submit();
            }

        }

    </script>
<?php $__env->stopSection(); ?>
<?php echo $__env->make('develop.layoutList', array_except(get_defined_vars(), array('__data', '__path')))->render(); ?>